Skip to content

feat(agy-proxy): warm conversation reuse (#480) - #767

Closed
dezren39 wants to merge 1 commit into
mainfrom
warm/agy-proxy-conversation-reuse
Closed

dezren39 wants to merge 1 commit into
mainfrom
warm/agy-proxy-conversation-reuse

Conversation

@dezren39

@dezren39 dezren39 commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

What

bin/agy-proxy.mjs spawned a fresh agy process per request and re-flattened the full conversation. It now reuses one agy conversation per logical chat:

  • Key: sha256(system prompt + first user message + resolved model)
  • Entry: {conversationId, fedCount, fedHashes, lastResponseHash, lastUsed}, persisted to warm-sessions.json next to endpoint.json; LRU 64 entries / 2h TTL; warmSessions added to /health.
  • Hit: only when the request history is a strict continuation of what was fed (fed prefix hashes match, echoed assistant message matches the stored response hash, count > fedCount) — then only the new turn(s) are sent via --conversation <id>.
  • Miss/mismatch: full-history fresh run, (re-)keyed on success.
  • Resume failure: non-zero exit OR the CLI's silent degradation (warning: conversation "<id>" not found on stderr, exit 0, fresh conversation with only the new turn — probed against agy 1.4.1) falls back to a full-history fresh run and still answers. Stream mode keeps the agy-proxy: failed agy run reported as successful 'stop' — stream handler never checks the exit code, non-stream masks failure when partial output exists #678 rule that already-streamed partial output cannot be retried.

How conversation ids are learned (probed, agy 1.4.1)

  • --output-format json → top-level {"conversation_id": "<id>", ...}
  • --output-format stream-json → {"event":"result","result":{"conversation_id": "<id>", ...}}
  • --conversation <id> resumes; --continue also exists but is global most-recent state, so it is not used for keyed reuse.

Tests

node --test bin/agy-proxy.test.mjs — 9/9 pass: the 5 existing #678 failure-detection tests plus 4 new #480 tests (continuation sends only the new turn in both modes, tampered/repeated history → fresh, failed warm resume → fresh answer, warm store persists across a proxy restart).

Deployment / measurement note

Sandbox + laptop deployment and before/after timings are being completed alongside this PR; the sandbox's agy is currently returning Authentication required (no ~/.gemini/oauth_creds.json present), so live timings there measure the auth-failure path until re-login. This PR does not touch opencode.jsonc or any other proxy.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

…odel (#480)

Resume one agy conversation per logical chat instead of re-flattening
the full history into a fresh CLI process per request. Conversation ids
are learned from the CLI's own output (json: top-level conversation_id;
stream-json: result.conversation_id) and resumed via --conversation with
only the new turn(s). Entries {conversationId, fedCount, fedHashes,
lastResponseHash, lastUsed} are persisted to warm-sessions.json next to
endpoint.json, LRU 64 / 2h TTL, and only used when the request history
is a strict continuation of what was fed. Any resume failure - non-zero
exit, or the CLI's silent 'conversation not found' degradation - falls
back to a full-history fresh run and still answers.
@dezren39
dezren39 requested a review from a team as a code owner October 24, 2026 16:09
@coderabbitai

coderabbitai Bot commented Oct 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 056e55cc-c999-4766-9cb0-91576aeae4eb
Commits

Reviewing files that changed from the base of the PR and between 15f4885 and d5792d7.

Files selected for processing: 2
  • bin/agy-proxy.mjs
  • bin/agy-proxy.test.mjs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T16:13:20.755981Z d5792d7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d5792d7680

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bin/agy-proxy.mjs
Comment on lines +360 to +365
if (messages[idx]?.role === 'assistant') {
if (entry.lastResponseHash && hashText(messageText(messages[idx])) !== entry.lastResponseHash) {
return { key, mode: 'fresh' };
}
idx++;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject warm continuation when the assistant echo is missing

After a single-message request [user A] produces response X, a subsequent request [user A, user B] passes the prefix check and resumes with B because the assistant echo is optional here. The resumed conversation still contains X even though the caller's supplied history omits it, so the answer is generated from a different history than requested. Previously, the initial single-message request did not populate the automatic session cache, so this follow-up ran with the supplied full history. Require the matching assistant echo before reusing the conversation; otherwise use a fresh run.

Useful? React with 👍 / 👎.

Comment thread bin/agy-proxy.mjs
Comment on lines +651 to 655
if (resumeNotFound && targetConvId) {
// Streamed answer came from a degraded fresh conversation
// that never saw the history: do not key it as fed.
invalidateWarm(warmPlan.key);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Report streamed unknown-conversation degradation as an error

When a warm streaming resume emits the recognized conversation ... not found warning, produces text, and exits zero, the retry is skipped because hasOutput is true. This branch only invalidates the cache; execution then bypasses the nonzero-exit error handler and sends finish_reason: "stop" for an answer generated without the previous history. I reproduced this with a stub emitting that warning, a text delta, and exit zero. Since the streamed text cannot be retracted, terminate with an SSE error rather than reporting successful completion.

Useful? React with 👍 / 👎.

Comment thread bin/agy-proxy.mjs
Comment on lines +474 to +476
const warmPlan = (!sessionInfo.conversationId && !sessionInfo.explicit)
? planWarmRequest(body.messages, fullName)
: { key: null, mode: 'fresh' };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep user-keyed sessions out of the automatic warm cache

On the first request with body.user, there is no cached conversation yet, so this condition enables warm tracking and registers the resulting conversation in both stores. Later requests for that user resume through sessionStore without updating or invalidating its warm entry. Consequently, after user Bob sends [A] → X and then [A, X, B], an anonymous request [A, X, C] passes the stale warm-prefix check and resumes Bob's conversation containing B, although B is absent from its supplied history. I reproduced this sequence with a stateful stub. Previously, user-keyed sessions never populated the automatic cache. Exclude requests with a user session key from warm tracking, or synchronize warm metadata whenever that conversation is resumed through the legacy store.

Useful? React with 👍 / 👎.

@dezren39

Copy link
Copy Markdown
Member Author

SHELVED by Drew's direction (2026-10-24): Antigravity is being consolidated to ONE provider fleet-wide (antigravity-ls, the warm daemon route); antigravity-agy is being disabled on both machines (kept in config as fallback). The warm conversation-reuse work here is complete but is NOT to be merged or shipped. Branch retained for reference; closing this PR without merging to shelve it. Part of the #480 warm-session program — codex (resume + app-server evaluation), muse (serve/MSP), design/clef keep-alive proceeded separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant